package com.chance.cc.crawler.development.bootstrap.eastday;

import com.chance.cc.crawler.core.CrawlerEnum;
import com.chance.cc.crawler.core.downloader.HttpConfig;
import com.chance.cc.crawler.core.filter.FilterUtils;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import com.chance.cc.crawler.development.controller.DevCrawlerController;

/**
 * @Author Zhao.Hhuan
 * @Date Create in 2020/11/24 15:42
 * @Description
 *      东方网
 **/
public class Eastday {
    public static void main(String[] args) {
        String domain = "eastday";
        String entranceUrl = "http://eastday.com/";
        String newsUrl = "http://news.eastday.com/gd2008/news/index.html";
        String jzUrl = "http://city.eastday.com/eastday/city/2016city/jz/index.html";

        DevCrawlerController.builder()
                .triggerInfo(domain,domain,System.currentTimeMillis(),domain)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(domain))
                .consoleResultPipeline()//控制台输出
//                .fileResultPipeline("D:\\chance\\log\\tets.log",true) //文件输出
                .requestRecord(createCrawlerRequestRecord(domain,entranceUrl))
                .requestRecord(createCrawlerRequestRecord(domain,newsUrl))
                .requestRecord(createCrawlerRequestRecordCount(domain,jzUrl))
                .build()
                .start();
    }

    public static CrawlerRequestRecord createCrawlerRequestRecord(String domain,String url){

        CrawlerRequestRecord crawlerRequestRecord = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(domain)
                .httpUrl(url)
                .recordKey(url)
                .httpConfig(HttpConfig.me(domain))
                .filter(CrawlerEnum.CrawlerRecordFilter.keyOrDateRange)
                .addFilterInfo(FilterUtils.memoryFilterKeyInfo(domain))
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24*1,null))
                .releaseTime(System.currentTimeMillis())
                .build();

        return crawlerRequestRecord;
    }

    public static CrawlerRequestRecord createCrawlerRequestRecordCount(String domain,String url){
        CrawlerRequestRecord crawlerRequestRecord = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(domain)
                .httpUrl(url)
                .recordKey(url)
                .httpConfig(HttpConfig.me(domain))
                .filter(CrawlerEnum.CrawlerRecordFilter.key)
                .addFilterInfo(FilterUtils.memoryFilterKeyInfo(domain))
                .releaseTime(System.currentTimeMillis())
                .build();

        return crawlerRequestRecord;
    }
}
